﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using RoadTeam.Model;
using RoadTeam.Enums;
using RoadTeam.SysInterface;
using RoadTeam.Pub;
namespace RoadTeam.BLL
{
    public class CsMaintenanceBll
    {
        public DataTable GetEmptyTable()
        {
            SqlWhere where = new SqlWhere();
            where.SelectColumn = @"  Top 0 * ";
            return CsMaintenance.Select(where, GlobalConfig.ConnectionString);
        }


        public bool InSertMaintenance(DataTable dt)
        {
            DataTable dt_Maintenance = FactoryClass.CreateCsMaintenance().GetEmptyTable();
            DataRow dr_Maintenance;
            foreach (DataRow dr in dt.Rows)
            {
                //SubCode,CreateDate,ServType,Content,Linkman,LinkTel,UnitFullName,
                //StaffName,Remark,App_Identities
                dr_Maintenance = dt_Maintenance.NewRow();
                dr_Maintenance[0] = dr["MaintenanceCode"];
                dr_Maintenance[1] = dr["MaintenanceDate"];
                dr_Maintenance[2] = dr["MaintenanceType"];
                dr_Maintenance[3] = dr["MaintenanceContent"];
                dr_Maintenance[4] = dr["MaintenanceContact"];
                dr_Maintenance[5] = dr["MaintenanceContactPhone"];
                dr_Maintenance[6] = dr["MaintenanceAddress"];
                dr_Maintenance[7] = dr["MaintenanceCreater"];
                dr_Maintenance[8] = dr["MaintenanceRemark"];
                dr_Maintenance[9] = dr["MaintenanceIdentities"];
                dr_Maintenance[10] = FactoryClass.CreateSmOrgan().GetOraganID( dr["OrganIdentifier"].ToString());
                if (dr["UnitIdentifier"] == null || String.IsNullOrEmpty(dr["UnitIdentifier"].ToString()))
                    dr_Maintenance[11] = DBNull.Value;
                else
                    dr_Maintenance[11] = FactoryClass.CreateRmUnit().GetUnitID(dr["UnitIdentifier"].ToString());
                dt_Maintenance.Rows.Add(dr_Maintenance);
            }
            FactoryClass.CreateCsMaintenance().InsertCsMaintenance(dt_Maintenance);
            return  CsMaintenance.InsertDatatable(dt, GlobalConfig.ConnectionString);
        }




    }
}
